﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Space_Conquest
{
    /// <summary>
    /// Represents one place / tile on a map
    /// </summary>
    class MapPoint
    {

        #region Private Members

        private int _x;
        private int _y;

        #endregion

        #region Constructors

        public MapPoint(int x, int y)
        {
            _x = x;
            _y = y;
        }

        // "Copy" constructor
        public MapPoint(MapPoint point)
        {
            _x = point.X;
            _y = point.Y;
        }

        #endregion

        #region Properties

        public int X
        {
            get
            {
                return _x;
            }
            set
            {
                _x = value;
            }
        }

        public int Y
        {
            get
            {
                return _y;
            }
            set
            {
                _y = value;
            }
        } 

        #endregion

        #region Methods

        public bool IsAdjacentTo(MapPoint secondPoint)
        {

            // First is Right of second
            if ((_x == (secondPoint.X - 1)) && (_y == secondPoint.Y))
                return true;

            // First is Left of second
            else if ((_x == (secondPoint.X + 1)) && (_y == secondPoint.Y))
                return true;

            // First is Below second
            else if ((_x == secondPoint.X) && (_y == (secondPoint.Y + 1)))
                return true;

            // First is Above second
            else if ((_x == secondPoint.X) && (_y == (secondPoint.Y - 1)))
                return true;

            // Not adjacent
            else
                return false;

        }

        public bool IsOnTopOf(MapPoint secondPoint)
        {
            // just check if rows and columns are the same
            return ((_y == secondPoint.Y) && (_x == secondPoint.X));
        }

        public double DistanceBetween(MapPoint secondPoint)
        {
            // Simple distance formula, returns double because of diagonals
            return Math.Sqrt(
                (((double)(secondPoint.Y - _y)) * ((double)(secondPoint.Y - _y))) 
                +
                (((double)(secondPoint.X - _x)) * ((double)(secondPoint.X - _x)))
                );
        }

        public override bool Equals(object point2)
        {
            MapPoint temp = (MapPoint)point2;
            return (X == temp.X && Y == temp.Y);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion

    }
}
